package com.it.schoolbookshop_back.mapper;

import com.it.schoolbookshop_back.entities.po.UserSettings;
import org.apache.ibatis.annotations.*;

/**
 * 用户设置数据访问层接口
 */
@Mapper
public interface UserSettingsMapper {
    
    /**
     * 根据用户ID获取设置
     * @param userId 用户ID
     * @return 用户设置
     */
    @Select("SELECT * FROM user_settings WHERE user_id = #{userId}")
    UserSettings getByUserId(@Param("userId") Integer userId);
    
    /**
     * 插入新的用户设置
     * @param userSettings 用户设置
     * @return 影响的行数
     */
    @Insert("INSERT INTO user_settings(user_id, notification_messages, notification_favorites, " +
            "notification_transactions) " +
            "VALUES(#{userId}, #{notificationMessages}, #{notificationFavorites}, " +
            "#{notificationTransactions})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserSettings userSettings);
    
    /**
     * 更新用户设置
     * @param userSettings 用户设置
     * @return 影响的行数
     */
    @Update("UPDATE user_settings SET " +
            "notification_messages = #{notificationMessages}, " +
            "notification_favorites = #{notificationFavorites}, " +
            "notification_transactions = #{notificationTransactions}, " +
            "updated_at = NOW() " +
            "WHERE user_id = #{userId}")
    int update(UserSettings userSettings);
    
    /**
     * 根据用户ID删除设置
     * @param userId 用户ID
     * @return 影响的行数
     */
    @Delete("DELETE FROM user_settings WHERE user_id = #{userId}")
    int deleteByUserId(@Param("userId") Integer userId);
} 